﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;
using ResourceLoadBalancer.DataAccess;

namespace ResourceLoadBalancer.WebServices.Contracts.Data
{
    [DataContract]
    public class ResourceURIDataContract
    {
        long id;
        string uri;
        string resourceHash;
        string hostName;
        string uriHash;
        string owner;
        DateTime lastModifiedDate;
        DateTime createdDate;
        DateTime inventoryDate;

        public ResourceURIDataContract(long id,
                                        string uri,
                                        string resourceHash,
                                        string hostName,
                                        string uriHash,
                                        string owner,
                                        DateTime lastModifiedDate,
                                        DateTime createdDate,
                                        DateTime inventoryDate)
        {
            this.id = id;
            this.uri = uri;
            this.resourceHash = resourceHash;
            this.hostName = hostName;
            this.uriHash = uriHash;
            this.owner = owner;
            this.lastModifiedDate = lastModifiedDate;
            this.createdDate = createdDate;
            this.inventoryDate = inventoryDate;
        }

        public ResourceURIDataContract(ResourceURI resourceURI)
        {
            ConvertEntityToDataContract(resourceURI);
        }

        public ResourceURIDataContract()
        { 
        }

        [DataMember]
        public long Id
        {
            get { return id; }
            set { id = value; }
        }

        [DataMember]
        public string URI
        {
            get { return uri; }
            set { uri = value; }
        }

        [DataMember]
        public string ResourceHash
        {
            get { return resourceHash; }
            set { resourceHash = value; }
        }

        [DataMember]
        public string HostName
        {
            get { return hostName; }
            set { hostName = value; }
        }

        [DataMember]
        public string URIHash
        {
            get { return uriHash; }
            set { uriHash = value; }
        }

        [DataMember]
        public string Owner
        {
            get { return owner; }
            set { owner = value; }
        }

        [DataMember]
        public DateTime LastModifiedDate
        {
            get { return lastModifiedDate; }
            set { lastModifiedDate = value; }
        }

        [DataMember]
        public DateTime CreatedDate
        {
            get { return createdDate; }
            set { createdDate = value; }
        }

        [DataMember]
        public DateTime InventoryDate
        {
            get { return inventoryDate; }
            set { inventoryDate = value; }
        }

        public ResourceURI ConvertDataContractToEntity()
        {
            ResourceURI entity = new ResourceURI();

            entity.Id = this.Id;
            entity.URI = this.URI;
            entity.ResourceHash = this.ResourceHash;
            entity.HostName = this.HostName;
            entity.URIHash = this.URIHash;
            entity.Owner = this.Owner;
            entity.LastModifiedDate = this.LastModifiedDate;
            entity.CreatedDate = this.CreatedDate;
            entity.InventoryDate = this.InventoryDate;

            return entity;
        }

        public void ConvertEntityToDataContract(ResourceURI entity)
        {
            this.Id = entity.Id;
            this.ResourceHash = entity.ResourceHash;
            this.URI = entity.URI;
            this.HostName = entity.HostName;
            this.URIHash = entity.URIHash;
            this.Owner = entity.Owner;
            this.LastModifiedDate = entity.LastModifiedDate;
            this.CreatedDate = entity.CreatedDate;
            this.InventoryDate = entity.InventoryDate;
        }
    }
}
